/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.quality4spl.fm.cvm.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import org.quality4spl.fm.cvm.CDMApplication;
import org.quality4spl.fm.cvm.CvmPackage;
import org.quality4spl.fm.cvm.VariableEntity;
import org.quality4spl.fm.cvm.VariableEntityPart;
import org.quality4spl.fm.cvm.VariableProperty;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Variable Entity</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.quality4spl.fm.cvm.impl.VariableEntityImpl#getAllProperties <em>All Properties</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.VariableEntityImpl#getParts <em>Parts</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.VariableEntityImpl#getApplications <em>Applications</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.VariableEntityImpl#getDiagram <em>Diagram</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class VariableEntityImpl extends VariabilityModelFolderImpl implements VariableEntity {
	/**
	 * The cached value of the '{@link #getParts() <em>Parts</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParts()
	 * @generated
	 * @ordered
	 */
	protected EList<VariableEntityPart> parts;

	/**
	 * The cached value of the '{@link #getApplications() <em>Applications</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getApplications()
	 * @generated
	 * @ordered
	 */
	protected EList<CDMApplication> applications;

	/**
	 * The cached value of the '{@link #getDiagram() <em>Diagram</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDiagram()
	 * @generated
	 * @ordered
	 */
	protected EObject diagram;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected VariableEntityImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return CvmPackage.Literals.VARIABLE_ENTITY;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<VariableProperty> getAllProperties() {
		// TODO: implement this method to return the 'All Properties' reference list
		// Ensure that you remove @generated or mark it @generated NOT
		// The list is expected to implement org.eclipse.emf.ecore.util.InternalEList and org.eclipse.emf.ecore.EStructuralFeature.Setting
		// so it's likely that an appropriate subclass of org.eclipse.emf.ecore.util.EcoreEList should be used.
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<VariableEntityPart> getParts() {
		if (parts == null) {
			parts = new EObjectContainmentEList<VariableEntityPart>(VariableEntityPart.class, this, CvmPackage.VARIABLE_ENTITY__PARTS);
		}
		return parts;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<CDMApplication> getApplications() {
		if (applications == null) {
			applications = new EObjectContainmentEList<CDMApplication>(CDMApplication.class, this, CvmPackage.VARIABLE_ENTITY__APPLICATIONS);
		}
		return applications;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EObject getDiagram() {
		return diagram;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetDiagram(EObject newDiagram, NotificationChain msgs) {
		EObject oldDiagram = diagram;
		diagram = newDiagram;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, CvmPackage.VARIABLE_ENTITY__DIAGRAM, oldDiagram, newDiagram);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDiagram(EObject newDiagram) {
		if (newDiagram != diagram) {
			NotificationChain msgs = null;
			if (diagram != null)
				msgs = ((InternalEObject)diagram).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - CvmPackage.VARIABLE_ENTITY__DIAGRAM, null, msgs);
			if (newDiagram != null)
				msgs = ((InternalEObject)newDiagram).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - CvmPackage.VARIABLE_ENTITY__DIAGRAM, null, msgs);
			msgs = basicSetDiagram(newDiagram, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CvmPackage.VARIABLE_ENTITY__DIAGRAM, newDiagram, newDiagram));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case CvmPackage.VARIABLE_ENTITY__PARTS:
				return ((InternalEList<?>)getParts()).basicRemove(otherEnd, msgs);
			case CvmPackage.VARIABLE_ENTITY__APPLICATIONS:
				return ((InternalEList<?>)getApplications()).basicRemove(otherEnd, msgs);
			case CvmPackage.VARIABLE_ENTITY__DIAGRAM:
				return basicSetDiagram(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case CvmPackage.VARIABLE_ENTITY__ALL_PROPERTIES:
				return getAllProperties();
			case CvmPackage.VARIABLE_ENTITY__PARTS:
				return getParts();
			case CvmPackage.VARIABLE_ENTITY__APPLICATIONS:
				return getApplications();
			case CvmPackage.VARIABLE_ENTITY__DIAGRAM:
				return getDiagram();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case CvmPackage.VARIABLE_ENTITY__PARTS:
				getParts().clear();
				getParts().addAll((Collection<? extends VariableEntityPart>)newValue);
				return;
			case CvmPackage.VARIABLE_ENTITY__APPLICATIONS:
				getApplications().clear();
				getApplications().addAll((Collection<? extends CDMApplication>)newValue);
				return;
			case CvmPackage.VARIABLE_ENTITY__DIAGRAM:
				setDiagram((EObject)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case CvmPackage.VARIABLE_ENTITY__PARTS:
				getParts().clear();
				return;
			case CvmPackage.VARIABLE_ENTITY__APPLICATIONS:
				getApplications().clear();
				return;
			case CvmPackage.VARIABLE_ENTITY__DIAGRAM:
				setDiagram((EObject)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case CvmPackage.VARIABLE_ENTITY__ALL_PROPERTIES:
				return !getAllProperties().isEmpty();
			case CvmPackage.VARIABLE_ENTITY__PARTS:
				return parts != null && !parts.isEmpty();
			case CvmPackage.VARIABLE_ENTITY__APPLICATIONS:
				return applications != null && !applications.isEmpty();
			case CvmPackage.VARIABLE_ENTITY__DIAGRAM:
				return diagram != null;
		}
		return super.eIsSet(featureID);
	}

} //VariableEntityImpl
